<?php

    if(empty($tabularIdx))
    {
        #dont display when used in multiform
        echo CHtml::openTag('div',array('class'=>'form'));
        echo CHtml::beginForm();
        echo YumHelper::requiredFieldNote();
    }

    echo CHtml::errorSummary($model); echo CHtml::errorSummary($profile);
/*
	$attribute = !empty($tabularIdx) ? "[{$tabularIdx}]username" : "username";
    echo CHtml::openTag('div',array('class'=>'row','style'=>'display: none;'));
    echo CHtml::activeLabelEx($model,$attribute);
	echo CHtml::activeTextField($model,$attribute,array('size'=>35,'maxlength'=>128));
	echo CHtml::error($model,$attribute);
    echo CHtml::closeTag('div');

	$attribute = !empty($tabularIdx) ? "[{$tabularIdx}]password" : "password";
    echo CHtml::openTag('div',array('class'=>'row'));
    echo CHtml::activeLabelEx($model,$attribute);
	echo CHtml::activePasswordField($model,$attribute,array('size'=>35,'maxlength'=>128));
	echo CHtml::error($model,$attribute);
    echo CHtml::closeTag('div');

	$attribute = !empty($tabularIdx) ? "[{$tabularIdx}]superuser" : "superuser";
    echo CHtml::openTag('div',array('class'=>'row'));
    echo CHtml::activeLabelEx($model,$attribute);
	echo CHtml::activeDropDownList($model,$attribute,YumUser::itemAlias('AdminStatus'),array('style'=>'width:235px',));
	echo CHtml::error($model,$attribute);
    echo CHtml::closeTag('div');

	$attribute = !empty($tabularIdx) ? "[{$tabularIdx}]status" : "status";
    echo CHtml::openTag('div',array('class'=>'row'));
	echo CHtml::activeLabelEx($model,$attribute);
	echo CHtml::activeDropDownList($model,$attribute,YumUser::itemAlias('UserStatus'),array('style'=>'width:235px',));
	echo CHtml::error($model,$attribute);
    echo CHtml::closeTag('div');
    */
    foreach($profile->loadProfileFields() as $field)
    {
        echo CHtml::openTag('div',array('class'=>'row'));
        $attribute = !empty($tabularIdx) ? "[{$tabularIdx}]{$field->varname}" : $field->varname;
        echo CHtml::activeLabelEx($profile,$attribute);
        if ($field->range) {
			echo CHtml::activeDropDownList($profile,
						$field->varname,
						YumProfile::range(Yii::t("UserModule.user",$field->range)),array('style'=>'width:235px',));
		}else{
			if ($field->field_type=="DATE") {
					$this->widget('zii.widgets.jui.CJuiDatePicker',
					array(
					'name'=>$field->varname,
					'value' => date(UserModule::$dateFormat, $profile->birthday),
					//  optional: jquery Datepicker options
					'options' => array(
						// how to change the input format? see http://docs.jquery.com/UI/Datepicker/formatDate
						'dateFormat'=>'mm-dd-yy',
			
						// user will be able to change month and year
						'changeMonth' => 'true',
						'changeYear' => 'true',
						// shows the button panel under the calendar (buttons like "today" and "done")
						'showButtonPanel' => 'false',
						// this is useful to allow only valid chars in the input field, according to dateFormat
						'constrainInput' => 'true',
						// speed at which the datepicker appears, time in ms or "slow", "normal" or "fast"
						'duration'=>'fast',
					),
							// optional: html options will affect the input element, not the datepicker widget itself
					'htmlOptions'=>array(
					'style'=>'width:235px;'
					)
		
			 // tells the widget to show the calendar inline
					)
					);
		}else{
        if ($field->field_type=="TEXT")
            echo CHtml::activeTextArea($profile,$attribute,array('style'=>'width:230px; height: 100px',));
        else
            echo CHtml::activeTextField($profile,$attribute,array('size'=>35,'maxlength'=>(($field->field_size)?$field->field_size:255)));
        echo CHtml::error($profile,$attribute);
		}
		}
        if($field->hint)
            echo CHtml::tag('div',array('class'=>'hint'),$field->hint,true);
        echo CHtml::closeTag('div');
		
    }
	$attribute = !empty($tabularIdx) ? "[{$tabularIdx}]username" : "username";
    echo CHtml::openTag('div',array('class'=>'row','style'=>'display: none;'));
    echo CHtml::activeLabelEx($model,$attribute);
	echo CHtml::activeTextField($model,$attribute,array('size'=>35,'maxlength'=>128));
	echo CHtml::error($model,$attribute);
    echo CHtml::closeTag('div');

	$attribute = !empty($tabularIdx) ? "[{$tabularIdx}]password" : "password";
    echo CHtml::openTag('div',array('class'=>'row'));
    echo CHtml::activeLabelEx($model,$attribute);
	echo CHtml::activePasswordField($model,$attribute,array('size'=>35,'maxlength'=>128));
	echo CHtml::error($model,$attribute);
    echo CHtml::closeTag('div');

	$attribute = !empty($tabularIdx) ? "[{$tabularIdx}]superuser" : "superuser";
    echo CHtml::openTag('div',array('class'=>'row'));
    echo CHtml::activeLabelEx($model,$attribute);
	echo CHtml::activeDropDownList($model,$attribute,YumUser::itemAlias('AdminStatus'),array('style'=>'width:235px',));
	echo CHtml::error($model,$attribute);
    echo CHtml::closeTag('div');

	$attribute = !empty($tabularIdx) ? "[{$tabularIdx}]status" : "status";
    echo CHtml::openTag('div',array('class'=>'row'));
	echo CHtml::activeLabelEx($model,$attribute);
	echo CHtml::activeDropDownList($model,$attribute,YumUser::itemAlias('UserStatus'),array('style'=>'width:235px',));
	echo CHtml::error($model,$attribute);
    echo CHtml::closeTag('div');
    /*
    if($this->module->hasModule('role'))
    {
        echo CHtml::openTag('div',array('class'=>'row'));
        echo CHtml::tag('p',array(),Yii::t('UserModule.user', 'User belongs to these roles'),true);
        $this->widget('YumModule.components.Relation',
			array('model' => $model,
			'relation' => 'roles',
			'style' => 'dropdownlist',
			'fields' => 'title',
			'showAddButton' => false
		));
        echo CHtml::closeTag('div');

        if($model->users)
        {
           echo CHtml::openTag('div',array('class'=>'row'));
           echo CHtml::tag('p',array(),Yii::t('UserModule.user', 'This user can administrate this users'),true);
           echo CHtml::closeTag('div');
           $this->widget('YumModule.components.Relation',
               array('model' => $model,
                   'relation' => 'users',
                   'style' => 'listbox',
                   'fields' => 'username',
                   'showAddButton' => false
            ));
        }
    }
*/
    if(empty($tabularIdx))
    {
        echo CHtml::openTag('div',array('class'=>'row buttons'));
        echo CHtml::submitButton($model->isNewRecord
            ? Yii::t('UserModule.user', 'Create')
            : Yii::t('UserModule.user', 'Save'));
        echo CHtml::closeTag('div');

        echo CHtml::endForm();
        echo CHtml::closeTag('div');
    }
?>
